/**
 * 检查报告管理初始化
 * 修改了项目 的itemDesc 为description
 */
var CdcExamination = {
    id: "CdcExaminationTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1,
    CdcExaminationId:-1
};

/**
 * 初始化表格的列
 */
CdcExamination.initColumn = function () {
    return [
        {field: 'selectItem', radio: true},
        {title: '就诊记录', field: 'episodeId', align: 'center', valign: 'middle', sortable: true,width: 100},
        {title: '索引码', field: 'xcode', align: 'center', valign: 'middle', sortable: true,width: 100},
        {title: '检查号', field: 'examNum', align: 'center', valign: 'middle', sortable: true,width: 100},
        {title: '状态', field: 'busExamReportStatus.description', align: 'center', valign: 'middle', sortable: true,width: 100},
        {title: '描述', field: 'description', align: 'center', valign: 'middle', sortable: true,width: 100},
        {title: '检查所见', field: 'examDesc', align: 'center', valign: 'middle', sortable: true,width: 100},
        {title: '诊断意见', field: 'resultDesc', align: 'center', valign: 'middle', sortable: true,width: 100},
        {title: '报告人', field: 'repUserName', align: 'center', valign: 'middle', sortable: true,width: 100},
        {title: '报告日期', field: 'repDate', align: 'center', valign: 'middle', sortable: true,width: 200},
        {title: '登记人', field: 'regUserName', align: 'center', valign: 'middle', sortable: true,width: 100},
        {title: '登记日期', field: 'regDate', align: 'center', valign: 'middle', sortable: true,width: 200},
        {title: '业务数据类型', field: 'data.description', align: 'center', valign: 'middle', sortable: true,width: 100},
        {title: '是否有效', field: 'isActive', align: 'center', valign: 'middle', sortable: true,width: 100, sortable: true,formatter:function(value,row,index) {
            return value?"是":"否";
        }}
    ];
};

/**
 * 检查是否选中
 */
CdcExamination.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if(selected.length == 0){
        Sys.info("请先选中表格中的某一记录！");
        return false;
    }else{
        CdcExamination.seItem = selected[0];
        return true;
    }
};

/**
 * 点击新增检查报告
 */
CdcExamination.add = function () {
    var index = Sys.open('新增检查报告',Sys.backendPath + '/cdc/cdcexamination/to_add',['800px', '420px']);
    this.layerIndex = index;
};

/**
 * 打开查看检查报告详情
 */
CdcExamination.edit = function (id) {
	var flag = false;
	if(id){
		flag = true;
	}else if (this.check()) {
        id = this.seItem.id;
        flag = true;
    }
	if (flag) {
    	var index = Sys.open('检查报告详情',Sys.backendPath + '/cdc/cdcexamination/to_update/' + id,['840px', '520px']);
        this.layerIndex = index;
    }
};

/**
 * 删除检查报告
 */
CdcExamination.del = function (id,name) {
	var flag = false;
	if(id){
		flag = true;
	}else if (this.check()) {
        id = this.seItem.id;
        name = this.seItem.name
        flag = true;
    }
	if (flag) {
        var operation = function(){
	        var ajax = new $ax(Sys.backendPath + "/cdc/cdcexamination/delete", function (data) {
	            Sys.success("删除成功!");
	            CdcExamination.table.refresh();
	        }, function (data) {
	            Sys.error("删除失败!" + data.responseJSON.message + "!");
	        });
	        ajax.set("cdcExaminationId",id);
	        ajax.start();
	    };
	    Sys.confirm("是否删除检查报告?",operation);
    }
};

/**
 * 查询检查报告列表
 */
CdcExamination.search = function () {
    var queryData = {};
    queryData['xcode'] = $("#xcode").val();
    queryData['examNum'] = $("#examNum").val();
    queryData['busExamReportStatusId'] = $("#busExamReportStatusId").val();
    queryData['description'] = $("#description").val();
    queryData['examDesc'] = $("#examDesc").val();
    queryData['resultDesc'] = $("#resultDesc").val();
    queryData['repUserName'] = $("#repUserName").val();
    queryData['repDate'] = $("#repDate").val();
    queryData['regUserName'] = $("#regUserName").val();
    queryData['regDate'] = $("#regDate").val();
    queryData['dataId'] = $("#dataId").val();
    queryData['isActive'] = $("#isActive").val();
    CdcExamination.table.refresh({query: queryData});
};

/**
 * by xzl
 */
CdcExamination.query = function () {
    if ((EpisodeIDTable.selEpisode)&&(EpisodeIDTable.selEpisode.id)) {
        var queryData=queryData = '{"NotQuery":"false","episodeId":"' + EpisodeIDTable.selEpisode.id + '"}';
        queryData = JSON.parse(queryData);
        CdcExamination.table.clear();
        CdcExamination.table.refresh({ query: queryData });
    }else{
        // CdcExamination.table.clear();
        Sys.info('请先选择患者！' );
    }
};
// CdcExamination.ClickRow=function (r,e,f){
//     CdcExamination.episodeId=r.id;
//     CdcExamination.table.clear();
//     CdcExamination.table.refresh({query: {episodeId:r.id}});
//
// };
/**
 * by xzl
 * 双击弹出检查报告详情的页面
 */
CdcExamination.DblClickRow=function (row, $ele, field){

    CdcExamination.edit(row.id);
    // alert(field);

};


$(function () {
    var defaultColunms = CdcExamination.initColumn();
    var table = new BSTable(CdcExamination.id, Sys.backendPath + "/cdc/cdcexamination/list", defaultColunms);
    table.setPaginationType("server");
    table.setPageSize(20);
    table.setShowRefresh(false);
    table.setShowColumns(false);
    table.setShowToggle(false);
    table.setShowExport(false);
    table.setSubHead(30);
    // 双击弹出检查报告详情的页面
    table.setOnDblClickRow(CdcExamination.DblClickRow);

    table.setQueryParams({ NotQuery: true });

    CdcExamination.table = table.init();
    CdcExamination.query();

});
